const checkIdCard = (idCard) => {
    if (idCard.length !== 18) {
        return false;
    }

    const checkDigit = idCard.slice(-1);
    const idCardWithoutCheckDigit = idCard.slice(0, -1);
    const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3];
    const sum = idCardWithoutCheckDigit
        .split("")
        .map((digit, index) => parseInt(digit) * weights[index])
        .reduce((acc, curr) => acc + curr, 0);
    const remainder = sum % 11;
    const expectedCheckDigit = [
        "1",
        "0",
        "X",
        "9",
        "8",
        "7",
        "6",
        "5",
        "4",
        "3",
        "2",
    ][remainder];
    return checkDigit === expectedCheckDigit;
};
